package com.compass.mobile.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.compass.mobile.R
import com.compass.mobile.databinding.ActivityConvenientFunctionBinding
import com.compass.mobile.framework.base.BaseVBActivity
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.utils.FocusViewUtils
import com.compass.mobile.ui.dialog.AgreementDialog
import com.compass.mobile.ui.viewModel.MainViewModel
import getStringFromResource
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * Description： 便捷功能activity
 * Date:2024/8/13 14:13
 */
class ConvenientFunctionActivity : BaseVBActivity<ActivityConvenientFunctionBinding>() {

    private val mainViewModel: MainViewModel by viewModels()

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, ConvenientFunctionActivity::class.java)
            context.startActivity(intent)
        }
    }


    override fun initView(savedInstanceState: Bundle?) {
        FocusViewUtils.scaleView(mBinding.llAutonomouslyTest, 1)
        FocusViewUtils.scaleView(mBinding.llFollowingRx, 1)
        FocusViewUtils.scaleView(mBinding.llMyConsultation, 1)
        FocusViewUtils.scaleView(mBinding.llNurse, 1)
        FocusViewUtils.scaleView(mBinding.llNursingOrder, 1)
        lifecycleScope.launch {
            delay(500)
            //延迟获取焦点
            mBinding.llAutonomouslyTest.requestFocus()
        }
    }

    override fun intListener() {

        mBinding.llAutonomouslyTest.onClick {

            mainViewModel.getHospitalConfig("content.inspectionService")

        }

        mBinding.llFollowingRx.onClick {
            //申请续方
            FollowingPrescriptionActivity.start(this)
        }

        mBinding.llMyConsultation.onClick {
            //我的预约
            MyAppointmentActivity.start(this)
        }

        mBinding.llNurse.onClick {
            //上门护理
            HomeCareActivity.start(this)
        }

        mBinding.llNursingOrder.onClick {
            //投诉建议
            ComplaintActivity.start(this)
        }


    }

    override fun initData() {
        mainViewModel.agreementLiveData.observe(this){ htmlDate->
            AgreementDialog.Builder(this,4, htmlDate)
                .setConfirm(getStringFromResource(R.string.ui_dialog_switch_call_type_positive))
                .setCancel(getStringFromResource(R.string.ui_dialog_switch_call_type_negative))
                .setonCancelListener {
                    it?.dismiss()
                }
                .setonConfirmListener {
                    it?.dismiss()
                    //自主开单
                    IndependentBillingActivity.start(this)
                }.create().show()

        }
    }


}